package com.sdleyou.treepro.common.service.impl;

import com.sdleyou.treepro.common.model.dao.ContactUsDO;
import com.sdleyou.treepro.common.model.dao.SloganDO;
import com.sdleyou.treepro.common.model.vo.ContactUsVO;
import com.sdleyou.treepro.common.model.vo.SloganVO;
import com.sdleyou.treepro.common.service.ContactManager;
import com.sdleyou.treepro.common.service.SloganManager;
import com.sdleyou.treepro.common.utils.DateUtil;
import com.sdleyou.treepro.common.utils.IdGen;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service
public class ContactManagerImpl implements ContactManager {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void createContact(String wxCode, String wxImg) {
        ContactUsDO contactUsDO = new ContactUsDO();
        contactUsDO.setCId(IdGen.uuid());
        contactUsDO.setWxCode(wxCode);
        contactUsDO.setWxImg(wxImg);
        contactUsDO.setGmtCreate(DateUtil.getDateline());
        contactUsDO.setGmtModified(DateUtil.getDateline());
        mongoTemplate.insert(contactUsDO);
    }

    @Override
    public ContactUsVO getContact() {
        ContactUsDO contactUsDO = mongoTemplate.findOne(new Query(), ContactUsDO.class);
        ContactUsVO contactUsVO = new ContactUsVO();
        if (contactUsDO != null) {
            BeanUtils.copyProperties(contactUsDO, contactUsVO);
        }
        return contactUsVO;
    }
}
